<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../node_modules/@vue/runtime-dom/dist/runtime-dom.global.js"></script>
    <div id="app"></div>
    <script>
        // 一个是dom平台下 ，一个是不依赖于平台 

        const { createApp, h,ref, reactive } = VueRuntimeDOM; // VueRuntimeCore
        let App = {
            setup() {
                const state = reactive({ count: 0 })
                let key = ref(true)
                const fn = () => {
                    // state.count++;
                }
                setTimeout(() => {
                    // state.count++;
                    // state.count++;
                    key.value = false
                }, 2000);
                return {
                    state,
                    fn,
                    key
                }
            },
            render(proxy) {
                console.log(proxy.key.value);
                // render会先执行取值操作 .fn、.count，这时候会触发对应的get
                // 将组件的effect收集依赖，然后执行h函数创建虚拟节点先span、在div。
                // 最后在循环递归子节点创建元素
                // return h(
                //     'div', 
                //     { onclick: proxy.fn, style: { background: 'red' } }, 
                //     [h('span', { style: { color: 'yellow' } }, proxy.state.count)])


                // 1 不同元素替换
                // return proxy.key.value?
                // h('div',[
                //     h('li',{key:'a'},'a'),
                //     h('li',{key:'b'},'b'),
                //     h('li',{key:'c'},'c'),
                // ]):
                // h('p','x')

                //    
                //  return proxy.key.value?
                // h('div',{style:{color: 'red'}},[h('span','hello'),h('span','hellos')]):
                // h('div',{style:{color: 'blue'}},h('span','hello'))


                //2 属性比对
                // return proxy.key.value?
                // h('div',{style:{color: 'yellow'}},'zy'):
                // h('div',{style:{color: 'red'}},'x')


                // 乱序比对
                // return proxy.key.value?
                // h('div',{style:{color: 'red'}},[
                //     h('li',{key:'a'},'a'),
                //     h('li',{key:'b'},'b'),
                //     h('li',{key:'c'},'c'),
                // ]):
                // h('div',{style:{color: 'blue'}},[
                //     h('li',{key:'d'},'d'),
                //     h('li',{key:'a'},'a'),
                //     h('li',{key:'b'},'b'),
                //     h('li',{key:'c'},'c'),
                // ])

                // 乱序比对
                return proxy.key.value?
                h('div',{style:{color: 'red'}},[
                    h('li',{key:'a'},'a'),
                    h('li',{key:'b'},'b'),
                    h('li',{key:'c',style:{color: 'green'}},'c'),
                    h('li',{key:'d'},'d'),
                    h('li',{key:'e'},'e'),
                    h('li',{key:'q'},'q'),
                    h('li',{key:'f'},'f'),
                    h('li',{key:'g'},'g'),
                ]):
                h('div',{style:{color: 'blue'}},[
                    h('li',{key:'a'},'a'),
                    h('li',{key:'b'},'b'),
                    h('li',{key:'e'},'e'),
                    h('li',{key:'c',style:{color: 'green'}},'c'),
                    h('li',{key:'d'},'d'),
                    h('li',{key:'h'},'h'),
                    h('li',{key:'f'},'f'),
                    h('li',{key:'g'},'g'),
                ])
            }
        }
        let app = createApp(App, { a: 1 }); // rootProps

        app.mount('#app')
    </script>
</body>

</html>